﻿using System;
using System.Collections.Generic;

namespace DataCoreTechnologies.SqlServer
{
   /// <summary>
   /// Contains information about a user created database type.
   /// </summary>
   public sealed class UserType
   {
      #region Public
      //Properties
      /// <summary>
      /// A number that uniquely identifies this class instance.
      /// </summary>
      public Guid InstanceId { get; internal set; }
      /// <summary>
      /// The schema this user type belongs to.
      /// </summary>
      public Schema Schema { get; internal set; }
      /// <summary>
      /// The title used to identify this user type within the database.
      /// </summary>
      public string Name { get; internal set; }
      /// <summary>
      /// When appropriate the maximum allowed size for this user type.
      /// </summary>
      public int MaxLength { get; internal set; }
      /// <summary>
      /// When appropriate the level of precision in this user type.
      /// </summary>
      public int Precision { get; internal set; }
      /// <summary>
      /// When appropriate the scale level in this user type.
      /// </summary>
      public int Scale { get; internal set; }
      /// <summary>
      /// When appropriate the name of the collation used by this user type.
      /// </summary>
      public string CollationName { get; internal set; }
      /// <summary>
      /// Indicator stating whether this user type allows null values.
      /// </summary>
      public Boolean IsNullable { get; internal set; }
      /// <summary>
      /// The system type this user type is derived from.
      /// </summary>
      public SystemType SystemType { get; internal set; }
      /// <summary>
      /// A collection of name / value pairs used to describe the purpose of this user type.
      /// </summary>
      public IEnumerable<ExtendedProperty> ExtendedProperties
      {
         get
         {
             for (int index = 0; index < _extendedProperties.Count; index++)
             {
                 yield return _extendedProperties[index];
             }
         }
      }
      #endregion
      #region Internal
      //Constructor
      /// <summary>
      /// Creates an instance of a user type.
      /// </summary>
      internal UserType()
      {
         InstanceId = System.Guid.NewGuid();
      }
      //Properties
      /// <summary>
      /// A number that uniquely identifies this user type within the database.
      /// </summary>
      internal int Id { get; set; }
      //Methods
      /// <summary>
      /// Associates a extended property to this user type.
      /// </summary>
      /// <param name="extendedProperty"></param>
      internal void AddExtendedProperty(ExtendedProperty extendedProperty) { _extendedProperties.Add(extendedProperty); }
      #endregion
      #region Private
      //Properties
      private List<ExtendedProperty> _extendedProperties = new List<ExtendedProperty>();
      #endregion
   }
}
